/*
 * @Author: biankai
 * @Date: 2021-10-19 16:16:18
 * @LastEditTime: 2021-11-03 12:19:48
 * @LastEditors: biankai
 * @FilePath: /gitee/devops_service/src/common/KubernetesConnect.ts
 */
import { Injectable, Inject } from '@nestjs/common';
import * as path from 'path';
import * as k8s from '@kubernetes/client-node';

@Injectable()
export class KubernetesConnect {
    private readonly envConfig: any;

    constructor() {
        const options = { folder: './src/common' };
        const filePath = `140config`;
        this.envConfig = path.resolve(__dirname, '../../', options.folder, filePath);
    }
    public init(type: any): any {
        const kc = new k8s.KubeConfig();
        kc.loadFromFile(this.envConfig)
        const k8sApi = kc.makeApiClient(type);
        return k8sApi;
    }
}
